package com.hhxy.stream;



import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;

public class ConcatTest {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,2,3);
        Stream<Integer> s1 = list.stream();
//        System.out.println(list);
        String[] st = {"张三","李四","王五"};
        Stream<String> s2 = Stream.of(st);
//        System.out.println(Arrays.toString(st));
       Stream.concat(s1,s2).forEach(s-> System.out.println(s));
       /*
       public static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b)
                    T：合并后Stream流，泛型上限(限制a要继承T) a,泛型上限((限制a要继承T) ) b
                    T如果不是a、b的父类就会报错
        */
       Stream<Integer> s3 = Stream.of(1,2,3);
        Stream<String> s4 = Stream.of("a","b","c");
        Stream<Object> s5 = Stream.concat(s3,s4);
       s5.forEach(s-> System.out.println(s));
       //注意事项：不能对同一个Stream流进行两次合并，编译时不会报错，一旦运行就会报：IllegalStateException异常
    }


}